package hihocoder;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class 小Hi小Ho的惊天大作战2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int task=scanner.nextInt();
		while (task-->0) {
			int N=scanner.nextInt();
			int M=scanner.nextInt();
			int[][] A=new int[N][M];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < M; j++) {
					A[i][j]=scanner.nextInt();
				}
			}
			//用1标记有雷，0标记没有雷，2代表不确定
			int[][] X=new int[N][M];
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < M; j++) {
					if(A[i][j]==0){
						for (int j2 = i-1; j2>=0&&j2<N&&j2 < 3; j2++) {
							for (int k = j-1; k>=0&&k<M&&k < 3; k++) {
								X[i][j]=0;
							}
						}
					}
				}
			}
		}
	}

}
